package main

import "fmt"

// 各种运算符
func operation() {
	fmt.Println()
	fmt.Println("=========operation========")
	fmt.Println()
	var int1, int2 = 21, 10
	var int3 int
	int3 = int1 + int2
	fmt.Println(int3)
	int3 = int1 - int2
	fmt.Println(int3)
	int3 = int1 * int2
	fmt.Println(int3)
	int3 = int1 / int2
	fmt.Println(int3)
	int3 = int1 % int2
	fmt.Println(int3)
	int1++
	fmt.Println(int1)
	int1 = 21
	int1--
	fmt.Println(int1)
	var tr = true
	var fa = false
	// go的&& 不是短路的  而且&只能用于位运算
	if tr && fa {
		fmt.Println("true")
	} else {
		fmt.Println("false")
	}
	var a int = 1
	// 高位舍弃，低位补0
	fmt.Println(a << 1)
	fmt.Println(a >> 1)
	// 指针
	var ptr *int
	// 指针指向a的地址
	ptr = &a
	fmt.Println(a)
	fmt.Println(*ptr)
	//  5	* / % << >> & &^
	//	4	+ - | ^
	//	3	== != < <= > >=
	//	2	&&
	//	1	||

	switch a {
	case 1:
		fmt.Println("1")
	case 2:
		fmt.Println("2")
	default:
		fmt.Println("d")
	}

	var c1, c2, c3 chan int
	var i1, i2 int
	select {
	case i1 = <-c1:
		fmt.Printf("received ", i1, " from c1\n")
	case c2 <- i2:
		fmt.Printf("sent ", i2, " to c2\n")
	case i3, ok := (<-c3): // same as: i3, ok := <-c3
		if ok {
			fmt.Printf("received ", i3, " from c3\n")
		} else {
			fmt.Printf("c3 is closed\n")
		}
	default:
		fmt.Printf("no communication\n")
	}
}
